• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            asm, c, c++ are my all
            -- Core In Computer
            posts - 139,  comments - 123,  trackbacks - 0

            /********************************************\
            |????歡迎轉(zhuǎn)載, 但請(qǐng)保留作者姓名和原文鏈接, 祝您進(jìn)步并共勉!???? |
            \********************************************/


            C++對(duì)象模型(8) - Chapter 3. The Semantics of Data
            ?

            作者: Jerry Cat
            時(shí)間: 2006/11/15
            鏈接:?
            http://www.shnenglu.com/jerysun0818/archive/2006/11/15/15185.html


            ;-----------------------------------------------------------------------
            ;Chapter 3. The Semantics of Data
            ;-----------------------------------------------------------------------
            Chapter 3. The Semantics of Data - 空類不空

            class X {};
            class Y : public virtual X {};
            class Z : public virtual X {};
            class A : public Y, public Z {};
            None of these classes contains any explicit data—any anything, in fact, except an inheritance
            relationship—so he apparently believed the size of each class should be 0. It wasn't,
            of course—not even the apparently benign class X:

            sizeof X yielded 1
            sizeof Y yielded 8
            sizeof Z yielded 8
            sizeof A yielded 12
            Let's look at each declaration in turn and see what's going on. An empty class, such as

            // sizeof X == 1
            class X {};
            in practice is never empty. Rather it has an associated size of 1 byte—a char member inserted
            by the compiler. This allows two objects of the class, such as

            X a, b;
            if ( &a == &b ) cerr << "yipes!" << endl;//to be allocated unique addresses in memory.哈!

            // sizeof Y == sizeof Z == 8
            class Y : public virtual X{};
            class Z : public virtual X{};
            On his machine, the size of both classes Y and Z is 8. This size, however, is partially machine dependent. It also depends in part on the compiler implementation being used. The given size of both class Y and class Z on any machine is the interplay of three factors:

            (1). Language support overhead. There is an associated overhead incurred in the language support of virtual base classes. Within the derived class, this overhead is reflected as some form of pointer, either to the virtual base class subobject or to an associated table within which either the address or offset to the virtual base class subobject is stored. On my correspondent's machine, the pointer is 4 bytes. (Virtual base classes are discussed in Section 3.4.)

            (2). Compiler optimization of recognized special cases. There is the 1 byte size of the virtual base class X subobject also present within Y (and Z). Traditionally, this is placed at the end of the "fixed" (that is, invariant) portion of the derived class. Some compilers now provide special support for an empty virtual base class (the paragraph following item 3 discusses this in more detail). Our correspondent's compiler, however, did not provide this special handling.

            (3). Alignment constraints. The size of class Y (and Z) at this point is 5 bytes. On most machines, aggregate structures have an alignment constraint so that they can be efficiently loaded from and stored to memory. On my correspondent's machine, alignment of an aggregate is on a 4-byte boundary. So class Y (and Z) requires 3 bytes of padding. The result is a final size of 8.

            The C++ object model representation for nonstatic data members optimizes for space and access time (and to preserve compatibility with the C language layout of the C struct) by storing the members directly within each class object. This is also true for the inherited nonstatic data members of both virtual and nonvirtual base classes, although the ordering of their layout is left undefined. Static data members are maintained within the global data segment of the program and do not affect the size of individual class objects.(靜態(tài)數(shù)據(jù)成員被放在全局?jǐn)?shù)據(jù)段, 并不影響單個(gè)類的大小)
            ?
            Only one instance of a static data member of a class exists within a program regardless of the number of times that class is an object of direct or indirect derivation. (The static data members of a template class behave slightly differently. See Section 7.1 for a discussion.)模板類的靜態(tài)數(shù)據(jù)成語(yǔ)有所不同

            類的大小讓你吃驚地"大"的原因來(lái)源于2方面:
            (1). Additional data members added by the compilation system to support some language functionality (primarily the virtuals)

            (2). Alignment requirements on the data members and data structures as a whole

            posted on 2006-11-15 16:55 Jerry Cat 閱讀(573) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理



            <2006年11月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(7)

            隨筆檔案

            最新隨筆

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久人人爽人人爽人人av东京热 | 精品国产乱码久久久久久浪潮| 久久精品国产亚洲AV麻豆网站 | 久久ZYZ资源站无码中文动漫| 狠狠色丁香久久综合五月| 久久精品国产亚洲av水果派| 国产99久久久国产精免费| 久久人妻少妇嫩草AV无码蜜桃| 无码乱码观看精品久久| 久久99精品久久久久久动态图| 91久久精品电影| 无码久久精品国产亚洲Av影片| 777久久精品一区二区三区无码| 思思久久99热只有频精品66| 久久精品国产半推半就| 久久精品国产亚洲AV不卡| 久久精品视频免费| 久久国产色AV免费看| 亚洲欧美另类日本久久国产真实乱对白| 日本人妻丰满熟妇久久久久久| 久久久久久国产精品美女 | 四虎国产精品免费久久5151| 九九精品久久久久久噜噜| 国产福利电影一区二区三区久久久久成人精品综合 | 狠狠色丁香婷婷综合久久来来去| 亚洲av日韩精品久久久久久a| 欧美一级久久久久久久大| aaa级精品久久久国产片| 中文字幕无码精品亚洲资源网久久| 精品久久久久久无码免费| www.久久热| 99久久婷婷国产综合亚洲| 久久综合狠狠综合久久| 久久人人添人人爽添人人片牛牛 | 久久久无码精品亚洲日韩蜜臀浪潮 | 成人午夜精品久久久久久久小说| 久久天天躁夜夜躁狠狠躁2022| 久久天天躁狠狠躁夜夜不卡| 青草影院天堂男人久久| 91精品国产综合久久香蕉 | 色欲av伊人久久大香线蕉影院|